//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
/*********************************************************************
Copyright:      (c) Intel Corporation, 2002, 2003
 
INTEL MAKES NO WARRANTY OF ANY KIND REGARDING THE CODE.  THIS CODE IS
LICENSED ON AN "AS IS" BASIS AND INTEL WILL NOT PROVIDE ANY SUPPORT,
ASSISTANCE, INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL DOES NOT
PROVIDE ANY UPDATES ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY
DISCLAIMS ANY WARRANTY OF MERCHANTABILITY, NONINFRINGEMENT, FITNESS
FOR ANY PARTICULAR PURPOSE, OR ANY OTHER WARRANTY.  INTEL DISCLAIMS
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGMENT OF ANY PROPRIETARY
RIGHTS, RELATING TO USE OF THE CODE.  NO LICENSE, EXPRESS OR IMPLIED,
BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS
GRANTED HEREIN.
*********************************************************************/

#ifndef Platform_h
#define Platform_h


#include "bulverde_def.h"



#define SB_SDRAM_FB_BEGIN		 MS_SDRAM_B0
//#define SB_SDRAM_FB_BEGIN           BV_SRAM
#define SB_SDRAM_FB_OFFSET     (0x00100000)                       // from bottom of memory
#define SB_C_VAR_OFFSET        (0x00100000)                       // starts at 0xA01000000 - from bottome of memory
#define SB_SDRAM_STACK_OFFSET  (128 * 1024)                       // from top of memory - 16K * 7 user modes 

#define SB_SDRAM_USER_START   (SB_SDRAM_FB_BEGIN + SB_SDRAM_FB_OFFSET + SB_C_VAR_OFFSET)  
#define SB_SDRAM_USER_END     (SB_SDRAM_FB_BEGIN + MS_SDRAMBANK0SIZE - SB_SDRAM_STACK_OFFSET - 4)
#define SB_SDRAM_USER_SIZE    (SB_SDRAM_USER_END - SB_SDRAM_USER_START)
#define SB_SRAM_USER_START    MS_SRAM
#define SB_SRAM_USER_END      (MS_SRAM + MS_SRAMSIZE - 4)
#define SB_SRAM_USER_SIZE     (SB_SRAM_USER_END - SB_SRAM_USER_START)


////////////////////////////////////////////////////////////////////////////////////////////
// Ending address of the DATA and BSS varibles of 'C'
////////////////////////////////////////////////////////////////////////////////////////////
extern unsigned int *_seg_BSS_end_;
extern unsigned int *Image$$ZI$$Limit;





// Some general / debugging output will be written to
//  OUTPUT1; must be 32 bits wide
#define OUTPUT1         (*LEDDAT1)

// Switches required by the boot code are 2 rotary switches (or 4 contiguous
//  bits from 1-bit DIP switches so that they can provide a
//  value in the range of 0-15 inclusive), and 8 1-bit DIP
//  switches.  The boot code is very likely to uses the rotary switches, and uses
//  SW1-SW8 as needed using lower numbers with higher priority.
//  In other words, be _certain_ to map LOW_ROTARY and HIGH_ROTARY.
#define LOW_ROTARY      (*GPSWR&0xF)          // mainstone sw9
#define HIGH_ROTARY     (*GPSWR&0xF0)         // mainstone sw5

#define SW3             (*GPSWR&0x100)      // mainstone sw3
#define SW4             (*GPSWR&0x200)      // mainstone sw4
#define SW6             (*GPSWR&0x400)      // mainstone sw6
#define SW7             (*GPSWR&0x800)      // mainstone sw7
#define SW8             (*GPSWR&0x1000)     // mainstone sw8
#define SW10            (*GPSWR&0x2000)     // mainstone sw10
#define SW11            (*GPSWR&0x4000)     // mainstone sw11
#define SW12            (*GPSWR&0x8000)     // mainstone sw12

#define MS_BOOT_ROM       0x00000000    // nCS0 - Boot ROM (Flash) */
#define MS_APP_FLASH      0x04000000    // nCS1 - Application Flash */
#define MS_Mainstone_REGS 0x08000000    // nCS2 - Mainstone Registers */
#define MS_SRAM           0x0A000000    // nCS2 - SRAM */
#define MS_ETHER_CONTR    0x0C000000    // nCS4 - Ethernet Controller 
#define MS_EXPAN_CONN     0x14000000    // nCS5 - Any future Expansion DaughterCard */
#define BV_SRAM           0x5C000000    //      - Internal SRAM - 256 KB
//#define MS_SDRAM_B0       0xA0000000    // nSDCS0 - MByte of SDRAM Bank 0 */
#define MS_SDRAM_B0       0xA1000000    // nSDCS0 - MByte of SDRAM Bank 0 */

#define MS_BOOTFLASHSIZE  0x02000000    // nCS0 - BOOT FLASH - 32 Mbytes
#define MS_APPFLASHSIZE   0x02000000    // nCS1 - APPLICATION FLASH - 32 Mbytes
#define MS_SRAMSIZE       0x00200000    // mCS2 - SRAM - 2 Mbytes
#define BV_SRAMSIZE       0x00040000    //      - SRAM - 256 Kbytes
#define MS_SDRAMBANK0SIZE 0x04000000    // nSDCS0 - SDRAM bank 0 - 64 Mbytes - 2P5VDC
//////////////////////////////////


/**********************/
/* External Registers */
/**********************/
#define LEDDAT1    (volatile unsigned long *)(0x08000010)  /* 32 bits of data for the HEX LEDs */
                                           // Read / Write	[31:0]	32 bits of LED Display
#define LEDDAT2    (volatile unsigned long *)(0x08000014)  /* 8 individual dot control (0=on, 1=off) */
                                           // Read / Write	[15:08]	8 bits for controlling the seven-segment LED decimal points.
                                           // reserved	[7:6] 
										   // Read / Write [5] Hex1L3 dot (0=on, 1=off)
										   // Read / Write [4] Hex1L2 dot (0=on, 1=off)
										   // Read / Write [3] Hex1L1 dot (0=on, 1=off)
										   // Read / Write [2] Hex0L3 dot (0=on, 1=off)
										   // Read / Write [1] Hex0L2 dot (0=on, 1=off)
										   // Read / Write [0] Hex0L1 dot (0=on, 1=off)
#define LEDCTRL    (volatile unsigned long *)(0x08000040)  /* Read / Write - LED Control Register (0=on, 1=off)*/
                                           // Read / Write	[15:08]	8 bits for blanking HEX LEDs
										   // Read / Write [7] D9 led
										   // Read / Write [6] D8 led
										   // Read / Write [5] D7 led
										   // Read / Write [4] D6 led
										   // Read / Write [3] D5 led
										   // Read / Write [2] D4 led
										   // Read / Write [1] D3 led
										   // Read / Write [0] D2 led
#define GPSWR      (volatile unsigned long *)(0x08000060)  /* Read only - On board switch state (0=dot, 1=no dot)*/
                                           // Read-Only	[15]	SW12
                                           // Read-Only	[14]	SW11
                                           // Read-Only	[13]	SW10
                                           // Read-Only	[12]	SW8
                                           // Read-Only	[11]	SW7
                                           // Read-Only	[10]	SW6
                                           // Read-Only	[9]		SW4
                                           // Read-Only	[8]		SW3
                                           // Read-Only	[7:4]	HEX SWITCH 1 (SW5) 
                                           // Read-Only	[3:0]	HEX SWITCH 0 (SW5) 
#define MSCWR1    (volatile unsigned long *)(0x08000080)  /* Misc. write registers */
                                           //             	[15:14]	Reserved
                                           // Read / Write	[13]	General-purpose LCD control signal - use varies with the LCD module being used 
                                           // Read / Write	[12]    Memory Stick power control (0=off, 1=on)
                                           // Read / Write	[11]    MultiMediaCard power control (0=off, 1=on)
                                           // Read / Write	[10]    SD/Memory Stick multiplexer control (0=SD/MMC, 1=Memory Stick)
                                           // Read / Write	[9]     PCMCIA/Baseband multiplex control (0=PCMCIA, 1=Baseband)
                                           // Read / Write	[8]     Bluetooth UART transceiver control (0=off, 1=on)
                                           // Read / Write	[7]     Bluetooth UART Data Terminal Ready (DTR) (0=false, 1=true)
                                           // Read / Write	[6:5]	IrDA transceiver mode control   
 										   //                        00 - full distance power
 										   //                        01 - shut down
 										   //                        10 - 2/3 distance power
 										   //                        11 - 1/3 distance power							
                                           // Read / Write	[4]	    IrDA transceiver SIR/FIR control (0=slow, 1=fast)
                                           // Read / Write	[3]     LED D1 (Green) (0=D1 on, 1=D1 off)
                                           // Read / Write	[2]	    PDC_CTL - reserved
                                           // Read / Write	[1]	    Silent alert motor control (0=off, 1=on)
                                           // Read / Write	[0]	    System software reset (0=reset deasserted, 1=reset asserted)
#define MSCWR2    (volatile unsigned long *)(0x08000084)  /* Misc. write registers */
                                           //             	[15:5]	Reserved
                                           // Read / Write	[4]	    USB client detection of connnect (0=enabled, 1=disabled)
                                           // Read / Write	[3]     I2S CODEC amplifier operational control (0=on, 1=off)
                                           // Read / Write	[2]	    AC'97 CODEC amplifier control (0=on, 1=off)
                                           // Read / Write	[1]	    Radio module power control (0=off, 1=on)
                                           // Read / Write	[0]	    Radio module wake-up signal (0=wake deasserted, 1=wake asserted)
#define MISCRD     (volatile unsigned long *)(0x08000090)  /* Misc. read registers */
                                           //             	[15:10]	Reserved
                                           // Read-Only	[9]	    AD17873 touch-screen digitizer nPENIRQ signal (0=low, 1=high)
                                           // Read-Only	[8]	    Memory Stick detection signal (0=inserted, 1=not present)
                                           // Read-Only	[7]	    SD/MMC card detection signal (0=inserted, 1=not present)
                                           // Read-Only	[6]     USIM card detection signal (0=inserted, 1=not present)
                                           // Read-Only	[5]     USB client cable status signal (0=inserted, 1=not present)
                                           // Read-Only	[4]     ADI7873 touch-screen digitizer busy (0=false, 1=true)	
                                           // Read-Only	[3]	    Bluetooth UART data set busy (0=false, 1=true)	
										   // Read-Only	[2]	    Bluetooth UART Ring Indicator (0=false, 1=true)	
										   // Read-Only	[1]	    Bluetooth UART Data Carrier Detect (0=false, 1=true)	
                                           // Read-Only	[0]     SD/MMC write-protect status (0=card wp, 1=card not wp)
#define INTMASKEN  (volatile unsigned long *)(0x080000C0)  /* Provides the enabling and masking of interrupts */
                                           //  (0=masked, 1=enabled)
                                           // Read / Write	[15]	PC-CARD socket 1 request IRQ
                                           // Read / Write	[14]	PC-CARD socket 1 status changed
                                           // Read / Write	[13]	PC-CARD socket 1 card detection
                                           //             	[12]	Reserved
                                           // Read / Write	[11]	PC-CARD socket 0 request IRQ
                                           // Read / Write	[10]	PC-CARD socket 0 status changed
                                           // Read / Write	[9]	    PC-CARD socket 0 card detection
                                           //             	[8]	    Reserved
                                           // Read / Write	[7]	    Expansion board IRQ
                                           // Read / Write	[6]	    Memory Stick detection
                                           // Read / Write	[5]	    AD17873 touch-screen digitizer IRQ
                                           // Read / Write	[4]	    AC'97 CODEC IRQ
                                           // Read / Write	[3]	    Ethernet controller IRQ
                                           // Read / Write	[2]	    USB client cable detection IRQ
                                           // Read / Write	[1]	    USIM card detection IRQ
                                           // Read / Write	[0]	    MMC/SD CARD	detection IRQ
#define INTSETCLR   (volatile unsigned long *)(0x080000D0)  /* Provides the setting and clearing of Interrupts */
                                           //  (0=cleared an interrupt, 1=set an interrupt)
                                           // Read / Write	[15]	PC-CARD socket 1 request IRQ
                                           // Read / Write	[14]	PC-CARD socket 1 status changed
                                           // Read / Write	[13]	PC-CARD socket 1 card detection
                                           // Read / Write	[12]	Reserved
                                           // Read / Write	[11]	PC-CARD socket 0 request IRQ
                                           // Read / Write	[10]	PC-CARD socket 0 status changed
                                           // Read / Write	[9]	    PC-CARD socket 0 card detection
                                           // Read / Write	[8]	    Reserved
                                           // Read / Write	[7]	    Expansion board IRQ
                                           // Read / Write	[6]	    Memory Stick detection
                                           // Read / Write	[5]	    AD17873 touch-screen digitizer IRQ
                                           // Read / Write	[4]	    AC'97 CODEC IRQ
                                           // Read / Write	[3]	    Ethernet controller IRQ
                                           // Read / Write	[2]	    USB client cable detection IRQ
                                           // Read / Write	[1]	    USIM card detection IRQ
                                           // Read / Write	[0]	    MMC/SD CARD	detection IRQ
#define PCMCIA0    (volatile unsigned long *)(0x080000E0)  /* PCMCIA control reg for socket 0 */
                                           //              [15:11]	Reserved
                                           // Read-Only    [10]	Interrupt request / ready signal - also available as a system interrupt source
                                           // Read-Only  	[9] 	VDD voltage sense signal / audio digital speaker
                                           // Read-Only   	[7:6]	VSS voltage sense signals
                                           // Read-Only   	[5]	    Card detection signal (0=present, 1=not present)
                                           // Read-Only   	[4]	    Card reset signal (0=deasserted, 1=asserted)
                                           // Read-Only   	[3:0]   MAX1602 power-supply control signals
                                           //    11 = A1VCC
                                           // 	  10 = A0VCC
                                           // 	  01 = A1VPP
                                           // 	  00 = A0VPP  Note:  See the MAX1602 data sheet for more information.
#define PCMCIA1    (volatile unsigned long *)(0x080000E4)  /* PCMCIA control reg for socket 1 */
                                           //              [15:11]	Reserved
                                           // Read-Only    [10]	Interrupt request / ready signal - also available as a system interrupt source
                                           // Read-Only  	[9] 	VDD voltage sense signal / audio digital speaker
                                           // Read-Only   	[7:6]	VSS voltage sense signals
                                           // Read-Only   	[5]	    Card detection signal (0=present, 1=not present)
                                           // Read-Only   	[4]	    Card reset signal (0=deasserted, 1=asserted)
                                           // Read-Only   	[3:0]   MAX1602 power-supply control signals
                                           //    11 = A1VCC
                                           // 	  10 = A0VCC
                                           // 	  01 = A1VPP
                                           // 	  00 = A0VPP  Note:  See the MAX1602 data sheet for more information.




#endif